package com.zjm.structural.flyweight.integer;

/**
 * 享元模式Integer
 */
public class IntegerTest {
    public static void main(String[] args) {
        // Integer.valueOf在-128到127之间，就是使用享元模式返回
        Integer x = Integer.valueOf(127);
        Integer y = new Integer(127);
        Integer z = Integer.valueOf(127);
        Integer w = new Integer(127);
        System.out.println(x.equals(y));
        System.out.println(x == y);
        System.out.println(x == z);
        System.out.println(w == x);
        System.out.println(w == y);

        // Integer.valueOf如果不在范围内，就new
        Integer x1 = Integer.valueOf(200);
        Integer x2 = Integer.valueOf(200);
        System.out.println(x1 == x2);
    }
}
